package com.qf.config;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;


/**
 * @ClassName Logger2Config
 * @Description TODO
 * @Author Windy
 * @Date 2022/9/21 19:13
 * @Version 1.0
 **/
@Configuration
@Aspect
public class Logger2Config {
    private static final Logger logger= LoggerFactory.getLogger(Logger2Config.class);

    @Pointcut("execution(* *.*.service.impl.*.*(..))")
    private void poin(){}

    @Around("poin()")
    public Object aroundLog(ProceedingJoinPoint proceedingJoinPoint){
        //开始记录日志
        logger.debug("==================================开始记录日志===============================");
        //记录时间和执行方法的名称
        MethodSignature signature = (MethodSignature) proceedingJoinPoint.getSignature();
        logger.debug("当前执行的方法为：{" +signature.getMethod().getName()+ "}");
        Object obj=null;
        try {
             obj = proceedingJoinPoint.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
            logger.debug("方法异常：{"+e.getMessage()+"}");
        }finally {
            logger.debug("=============================记录结束====================================");
            return obj;
        }
    }
}
